package com.desmart.renjiao.employeeself;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.desmart.renjiao.R;
import com.desmart.renjiao.contants.Constants;
import com.desmart.renjiao.main.adapter.HomeIconAdapter;
import com.desmart.renjiao.main.adapter.HomeItemType;
import com.desmart.renjiao.main.bean.HomeIcons;
import com.desmart.renjiao.main.bean.Title;
import com.lemon.library.common.ARoutePath;
import com.lemon.library.common.router.Contanst;
import com.lemon.library.common.router.JumpUtils;
import com.lemon.library.utils.FullyGridLayoutManager;
import com.lemon.library.utils.ToastUtils;

import java.util.List;

public class EmployeeTypeAdapter extends BaseMultiItemQuickAdapter<HomeItemType,BaseViewHolder> {

    private OnEmployeeItemClick onEmployeeItemClick;

    public void setOnEmployeeItemClick(OnEmployeeItemClick onEmployeeItemClick) {
        this.onEmployeeItemClick = onEmployeeItemClick;
    }

    public EmployeeTypeAdapter(List<HomeItemType> data) {
        super(data);
        addItemType(HomeItemType.TITLE, R.layout.main_home_type_title);
        addItemType(HomeItemType.ICON, R.layout.main_home_type_icon);
        addItemType(HomeItemType.EMPTY, R.layout.main_home_type_empty);
    }

    @Override
    protected void convert(BaseViewHolder helper, HomeItemType item) {
        switch (helper.getItemViewType()) {
            case HomeItemType.TITLE:
                bindTitle(helper, item);
                break;
            case HomeItemType.ICON:
                bindIcon(helper,item);
                break;
        }
    }

    private void bindIcon(BaseViewHolder helper, HomeItemType item) {
        RecyclerView recyclerview = helper.itemView.findViewById(R.id.recyclerview);
        recyclerview.setLayoutManager(new FullyGridLayoutManager(mContext,4));
        HomeIcons icons = (HomeIcons) item;
        List<HomeIcons.Icon> list = icons.getList();
        HomeIconAdapter iconAdapter = new HomeIconAdapter(list);
        iconAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                int title = list.get(position).getTitle();
                if (onEmployeeItemClick != null)
                    onEmployeeItemClick.onClickIcon(title);
            }
        });
        recyclerview.setAdapter(iconAdapter);
    }

    private void bindTitle(BaseViewHolder helper, HomeItemType item) {
        TextView tvTitle = helper.itemView.findViewById(R.id.tv_title);
        Title title = (Title) item;
        tvTitle.setText(title.getName());
    }


    public interface OnEmployeeItemClick{

        void onClickIcon(int title);

    }
}
